using UnityEngine;
using UnityEngine.SceneManagement;

public class RandomSceneSwitcher : MonoBehaviour
{
    public float checkInterval = 1.0f; // 检查间隔时间
    public float probability = 0.1f; // 触发场景切换的概率
    public float probability1 = 0.3f;
    public float probability2 = 0.5f;

    private float timer = 0.0f;

    private void Update()
    {
        timer += Time.deltaTime;

        if (timer >= checkInterval)
        {
            timer = 0.0f;
            CheckForSceneSwitch();
        }
    }

    private void CheckForSceneSwitch()
    {
        // 生成一个0到1之间的随机数
        float randomValue = Random.value;
        Debug.Log(randomValue);
        // 如果随机数小于设定的概率，则触发场景切换
        if (randomValue < probability || randomValue < probability1 || randomValue < probability2)
        {
            SwitchToRandomScene();
        }
    }

    private void SwitchToRandomScene()
    {
        // 获取所有可用场景的名称
        // string[] sceneNames = SceneManager.GetSceneNamesInBuildSettings();

        // 从可用场景中随机选择一个
        // int randomIndex = Random.Range(0, sceneNames.Length);
        // string randomSceneName = sceneNames[1];

        // 加载新场景
        SceneManager.LoadScene(1);
    }
}